
(function () {
    console.log("预警修改文件");
    let now_open_diag = {}
    now_open_diag.API_URL = ' '
    document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
    let dataPush = []
    let flag = false
    function render(obj) {
        const {
            tagName,
            children,
            className,
            attrs
        } = obj;
        const dom = document.createElement(tagName);
        if (className) {
            dom.className = className;
        }
        if (attrs) {
            for (let key in attrs) {
                if (key.startsWith('on')) {
                    dom[key.toLocaleLowerCase()] = attrs[key];
                } else {
                    dom.setAttribute(key, attrs[key]);
                }
            }
        }
        if (children && children.length > 0) {
            if (typeof children == 'string') {
                const text = document.createTextNode(children);
                dom.appendChild(text);
            } else {
                children.forEach(item => {
                    dom.appendChild(render(item));
                })
            }
        }
        return dom;
    }
    const initEvent = (str) => { //
        //获取事件元素
        let oFootBtns = document.getElementById(str).children //底部菜单 btns
        if (str == "zbf_foot_btns") {
            now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 1].style.display = "none"
            // now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 2].style.display = "none"
        }
        for (let i = 0; i < oFootBtns.length; i++) {
            oFootBtns[i].onclick = () => {
                for (let ii = 0; ii < oFootBtns.length; ii++) {
                    oFootBtns[ii].className = ""
                }
                oFootBtns[i].className = "active"
                if (str == "zbf_r_btns") {
                    // if (i == 8) {
                    //     for (let o = 6; o < 14; o++) {
                    //         scene.children[2].children[o].visible = false
                    //     }
                    // } else {
                    //     scene.children[2].children[13 - i].visible = !scene.children[2].children[13 - i].visible
                    // }
                } else {
                    function closeDiag() {
                        timer ? clearInterval(timer) : ""
                        frist ? clearInterval(frist) : ""
                    }
                    switch (i) {
                        case 0:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("首页", 15, "SJDL_IFS_DATA.prj", "首页")
                                window.location.href = "/index.html"
                            }, 200)
                            break;
                        case 1:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("全炉膛温度场", 11, "SJDL_IFS_DATA.prj", "全炉膛温度场")
                                window.location.href = "/ranshaoshuzihuajiance.html"
                            }, 200)

                            break;
                        case 2:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("横截面", 6, "SJDL_IFS_DATA.prj", "横截面")
                                window.location.href = "/hjm.html"
                            }, 200)

                            break;
                        case 3:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("燃烧稳定性监测", 7, "SJDL_IFS_DATA.prj", "燃烧稳定性监测")
                                window.location.href = "/ranshaowendingxing.html"
                            }, 200)

                            break;
                        case 4:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉分配率", 9, "SJDL_IFS_DATA.prj", "煤粉分配率")
                                window.location.href = "/meifen.html"
                            }, 200)

                            break;
                        case 5:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉颗粒度分布", 8, "SJDL_IFS_DATA.prj", "煤粉颗粒度分布")
                                window.location.href = "/main/dcimgs/gl/main.html"
                            }, 200)

                            break;
                        case 6:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警信息", 12, "SJDL_IFS_DATA.prj", "预警信息")
                                window.location.href = "/yujing.html"
                            }, 200)

                            break;
                        case 7:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("历史数据", 10, "SJDL_IFS_DATA.prj", "历史数据")
                                window.location.href = "/history.html"
                            }, 200)

                            break;
                        case 8:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("历史数据", 10, "SJDL_IFS_DATA.prj", "历史数据")
                                window.location.href = "/dcsHistory.html"
                            }, 200)

                            break;
                        case 9:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警阈值配置修改", 14, "SJDL_IFS_DATA.prj", "预警阈值配置修改")
                                window.location.href = "/canshushezhi.html"
                            }, 200)

                            break;
                        default:

                    }

                }
            }
        }
    }

    let dataList = ['A1燃烧温度']
    initEvent('zbf_foot_btns') //底部菜单 btns
    // let c_form = eval('formview_' + now_open_diag.fmname)

    let mon = () => moment(new Date()).subtract('5', 'second').format('YYYY-MM-DD HH:mm:ss')
    let mons = () => moment(new Date()).subtract('2', 'minute').format('YYYY-MM-DD HH:mm:ss')
    let monss = () => moment(new Date()).subtract('1', 'minute').format('YYYY-MM-DD HH:mm:ss')
    let objdemo = []
    let obj = {
        "endTime": mon(),
        "interval": "1",
        "pointIndexList": objdemo,
        "startTime": mons()
    }
    let objsdemo = []
    let objs = {
        "endTime": mon(),
        "interval": "1",
        "pointInfoList": ['A1_IRAC1::A1 红外特征1'],
        "startTime": monss(),
    }
    let objDcsDemo = []
    let objDcs = {
        "endTime": mon(),
        "interval": "1",
        "pointIndexList": objDcsDemo,
        "startTime": monss(),
    }
    let frist = setTimeout(() => {
        shishipointName()
        soucreInit()
        setSelcetQudata()
        initArither()
        initTanChuan()
        // dataRefresh(obj)
        // shishidatarefsresh(objs)
        // pointName()
        // DcsHistoys()
        getTr()
        curveData()
        getData()
    }, 500)

    let timer = setInterval(() => {
        document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
        // shishidatarefsresh(objs)
        // changeName()
        initEditEvent()
        hansHundes()
        // shishichangeName()
    }, 1000)
    function $(el, all = false) {
        if (all) return document.querySelectorAll(el);
        return document.querySelector(el);
    }
    function Request(baseUrl = '', time = 1000) {
        this.baseUrl = baseUrl;

        function request(url, option = {}) {
            return new Promise(async (resolve, reject) => {
                try {
                    const response = await fetch(baseUrl + url, option);
                    if (response.status == '200') {
                        const data = await response.json();
                        if (data.code == '200') {
                            resolve(data);
                        } else {
                            alert(data.message)
                            reject(data.message || '请求失败');
                        }
                    } else {
                        reject(response);
                    }
                } catch (e) {
                    reject(e);
                }
            })
        }

        this.post = function (url, data) {
            return request(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
        }

        this.get = function (url) {
            return request(url, {
                method: 'GET'
            })
        }
    }
    Request.createRequest = function (baseUrl) {
        return new Request(baseUrl);
    }
    const request = Request.createRequest(now_open_diag.API_URL);
    var csszDataObj = []
    const getData = (requestData) => {

        // 初始化表单数据
        request.post('/spf/visit/getParmSet', {}).then(res => {
            //console.log(res);
            setData(res.data)
            csszDataObj = res.data
        })

    }
    // 防抖
    function antiShake(fn, interval) {
        var delay = delay || 200;
        var timer;
        return function () {
            var th = this;
            var args = arguments;
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(function () {
                timer = null;
                fn.apply(th, args);
            }, delay);
        };

    }
    const setData = (arr) => { //
        let oEditCurs = document.getElementById('zbf_edit_cur').children
        let l_title = ["low", "up", "warnLow", "warnUp", "owerLow", "owerUp"]
        for (let i = 0; i < oEditCurs.length; i++) {
            //console.log(oEditCurs[i].children);
            for (let oi = 1; oi < oEditCurs[i].children.length; oi++) {
                // console.log(oi,arr[oi-1],arr[oi-1][l_title[i]]);
                let str = ""
                if (oi == 1) {
                    str = arr[i][l_title[0]] + (arr[i][l_title[1]] ? " ~" + arr[i][l_title[1]] : "")
                } else if (oi == 2) {
                    str = arr[i][l_title[2]] + (arr[i][l_title[3]] ? " +" + arr[i][l_title[3]] : "")
                } else {
                    str = arr[i][l_title[4]] + (arr[i][l_title[5]] ? " +" + arr[i][l_title[5]] : "")
                }

                oEditCurs[i].children[oi].innerHTML = str
                oEditCurs[i].children[oi].setAttribute("data-param", arr[i].id)
            }
        }
    }
    const editValue = (requestData) => { //
        request.post('/spf/visit/updateParam', JSON.parse(requestData)).then(res => {
            //console.log(res);

        })

    }
    const initEditEvent = () => { //
        let oEditCurs = document.getElementById('zbf_edit_cur').children
        for (let i = 0; i < oEditCurs.length; i++) {
            // console.log(	oEditCurs[i].children);
            for (let oi = 1; oi < oEditCurs[i].children.length; oi++) {
                // oEditCurs[i].children[oi].style.color="blue"
                oEditCurs[i].children[oi].onclick = (e) => {
                    let t_title = ["正常区域值", "预警值", "超限值"]
                    let l_title = ["A层燃烧温度(℃)", "B、C层燃烧温度(℃)", "D、E、F层燃烧温度(℃)", "着火距离(mm)", "稳定性(%)", "煤粉分配率(%)"]
                    // console.log(document.getElementById('editH1'));
                    // console.log(e.x,e.y);
                    let oEditDiv = document.getElementById('editDiv')

                    let oEditDivH1 = document.getElementById('editH1')
                    oEditDivH1.innerHTML = t_title[oi - 1] + l_title[i]
                    // console.log(oEditDiv.children[1].children[1]);
                    oEditDiv.style.display = "block"
                    console.log(l_title[i])
                    if (l_title[i] == "稳定性(%)" || (l_title[i] == "煤粉分配率(%)" && t_title[oi - 1] == "正常区域值")) {
                        oEditDiv.children[1].children[1].style.display = "none"
                    } else {
                        oEditDiv.children[1].children[1].style.display = "block"
                    }
                    oEditDiv.style.background = "#333"
                    oEditDiv.style.top = e.y - 230 + "px"
                    oEditDiv.style.left = oi > 22 ? e.x - 350 + "px" : e.x - 170 + "px"
                    if (oi == 1) {
                        oEditDiv.children[1].children[0].value = Number(oEditCurs[i].children[oi].innerHTML.split("~")[0])
                        oEditDiv.children[1].children[1].value = oEditCurs[i].children[oi].innerHTML.split("~").length > 1 ? Number(oEditCurs[i].children[oi].innerHTML.split("~")[1]) : ""
                        console.log()
                    } else {
                        oEditDiv.children[1].children[0].value = Number(oEditCurs[i].children[oi].innerHTML.split(" ")[0])
                        oEditDiv.children[1].children[1].value = oEditCurs[i].children[oi].innerHTML.split(" ").length > 1 ? Number(oEditCurs[i].children[oi].innerHTML.split(" ")[1]) : ""
                    }
                    // console.log(oEditDiv.children[1].children[1].value = oEditCurs[i].children[oi].innerHTML.split("-").length)
                    // console.log(oEditCurs[i].children[oi].innerHTML.split("-"), oEditDiv.children[1].children[0].value, oEditDiv.children[1].children[1].value ? "存在" : "no");

                    oEditDiv.setAttribute("data-param", "[" + oi + "," + i + "]")
                    oEditDiv.children[1].children[2].onclick = () => {
                        oEditCurs[i].children[oi].innerHTML = Number(oEditDiv.children[1].children[0].value)
                        console.log(oEditCurs[i].children[oi].innerHTML)
                        if (oi == 1) {
                            oEditCurs[i].children[oi].innerHTML = oEditDiv.children[1].children[0].value + (oEditDiv.children[1].children[1].value ? "~" + oEditDiv.children[1].children[1].value : '')

                        } else {
                            oEditCurs[i].children[oi].innerHTML = oEditDiv.children[1].children[0].value + (oEditDiv.children[1].children[1].value ? " " + oEditDiv.children[1].children[1].value : "")
                        }

                        oEditCurs[i].children[oi].style.borderColor = "yellow"
                        oEditDiv.style.display = "none"
                        let id = oEditCurs[i].children[oi].getAttribute("data-param")
                        //console.log(id, oi);
                        let l_title = ["low", "up", "warnLow", "warnUp", "owerLow", "owerUp"]
                        let obj = {
                            id
                        }
                        if (oi == 1) {
                            obj[l_title[0]] = oEditDiv.children[1].children[0].value.replace(/\+/g, "")
                            oEditDiv.children[1].children[1].value.replace(/\+/g, "") ? obj[l_title[1]] = oEditDiv.children[1].children[1].value.replace(/\+/g, "") : ""

                        } else if (oi == 2) {
                            obj[l_title[2]] = oEditDiv.children[1].children[0].value.replace(/\+/g, "")
                            oEditDiv.children[1].children[1].value.replace(/\+/g, "") ? obj[l_title[3]] = oEditDiv.children[1].children[1].value.replace(/\+/g, "") : ""
                        } else if (oi == 3) {
                            obj[l_title[4]] = oEditDiv.children[1].children[0].value.replace(/\+/g, "")
                            oEditDiv.children[1].children[1].value.replace(/\+/g, "") ? obj[l_title[5]] = oEditDiv.children[1].children[1].value.replace(/\+/g, "") : ""
                        }
                        editValue(JSON.stringify(obj))
                    }
                    // oEditCurs[i].children[oi].style.borderColor="red"
                }
                oEditCurs[i].children[oi].onmouseenter = () => {
                    oEditCurs[i].children[oi].style.borderColor = "red"
                }
                oEditCurs[i].children[oi].onmouseout = () => {
                    oEditCurs[i].children[oi].style.borderColor = "#040a18"
                }
            }
        }
    }
    // 曲线参数修改动态下拉框
    function setSelcetQudata() {
        const myselect = document.querySelector('.qxcsselect')
        request.post('/api/sjdl/option/getFloor').then(res => {
            let arr = res.data.map(item => {
                if (item.floorName.startsWith('SOFA')) {
                    return {
                        floorName: item.floorName,
                        id: item.floorName
                    }
                } else {
                    return {
                        floorName: item.floorName + '层燃烧器',
                        id: item.floorName
                    }
                }
            })
            myselect.innerHTML = arr.map(item => `<option value="${item.id}">${item.floorName}</option>`).join('')
        })
    }
    // 曲线参数修改
    const hansHundes = () => {
        const myselect = document.querySelector('.qxcsselect')
        const setCurres = document.querySelector('#zbf_edit_cur1').children
        let t_titles = ["A1", "A2", "A3", "A4"]
        let canshupostCont = document.querySelectorAll('.canshupost-cont')

        let l_titles = ["温度分析值", "着火距离分度值", "燃烧稳定性分度值", "温度时间常数", "着火距离时间常数", "燃烧稳定性时间常数"]
        let eventUi = document.querySelectorAll('.envent_u1 span')
        let TanChangBoxCanshupostCont = document.querySelectorAll('.TanChangBox-canshupost-cont') // 算法
        let canshupostBox = document.querySelectorAll('.canshupost-box .canshupost-center')
        // select 下拉值
        myselect.onchange = (e) => {
            e.stopPropagation()
            console.log("1111")
            t_titles = t_titles.map((item, index) => {
                return item = myselect[myselect.selectedIndex].value + (index + 1)
            })

            for (let i = 1; i < eventUi.length; i++) {
                eventUi[i].innerHTML = t_titles[i - 1]
            }

            for (let index = 0; index < canshupostCont.length; index++) {
                for (let j = 0; j < canshupostCont[index].children.length; j++) {
                    canshupostCont[index].children[j].children[0].innerHTML = t_titles[j]
                }
            }
            // scoure点切换
            for (let id = 0; id < TanChangBoxCanshupostCont.length; id++) {
                for (let j = 0; j < TanChangBoxCanshupostCont[id].children.length; j++) {
                    TanChangBoxCanshupostCont[id].children[j].children[0].innerHTML = t_titles[j]
                }
            }
            scoureSlecet(myselect[myselect.selectedIndex].value)
            selectAst(myselect[myselect.selectedIndex].value)
            // 调用曲线参数接口
            getTr(myselect[myselect.selectedIndex].value)
        }
        for (let i = 0; i < setCurres.length; i++) {
            for (let j = 1; j < setCurres[i].children.length; j++) {
                setCurres[i].children[j].onclick = (e) => {
                    console.log("1111")
                    e.stopPropagation()
                    let oEditDiv = document.getElementById('editDiv1')
                    console.log(oEditDiv)
                    let oEditDivH1 = document.getElementById('editH12')
                    oEditDivH1.innerHTML = myselect.value + j + "-" + l_titles[i]
                    oEditDiv.style.display = "block"

                    // if (l_title[i] == "燃烧稳定性分度值" || (l_title[i] == "煤粉分配率(%)" && t_title[oi - 1] == "正常区域值")) {
                    //     oEditDiv.children[1].children[1].style.display = "none"
                    // } else {
                    //     oEditDiv.children[1].children[1].style.display = "block"
                    // }
                    oEditDiv.style.background = "#333"
                    // oEditDiv.style.top = e.y - 650 + "px"
                    // oEditDiv.style.left = j > 22 ? e.x - 300 + "px" : e.x - 150 + "px"
                    // console.log(e.y, e.x)
                    oEditDiv.style.top = e.y - 200 + "px"
                    oEditDiv.style.left = j > 22 ? e.x - 600 + "px" : e.x - 1250 + "px"
                    if (j == 1) {
                        oEditDiv.children[1].children[0].value = setCurres[i].children[j].innerHTML.split("-")[0]
                        // oEditDiv.children[1].children[1].value =  setCurres[i].children[j].innerHTML.split("-").length > 1 ? setCurres[i].children[j].innerHTML.split("-")[1] : ""
                    } else {
                        oEditDiv.children[1].children[0].value = setCurres[i].children[j].innerHTML.split(" ")[0]
                        // oEditDiv.children[1].children[1].value =  setCurres[i].children[j].innerHTML.split(" ").length > 1 ?  setCurres[i].children[j].innerHTML.split("")[1] : ""
                    }
                    // oEditDiv.setAttribute("data-params", "[" + j + "," + i + "]")
                    oEditDiv.children[1].children[1].onclick = (e) => {
                        e.stopPropagation()
                        console.log("333")
                        setCurres[i].children[j].innerHTML = oEditDiv.children[1].children[0].value
                        if (j == 1) {
                            setCurres[i].children[j].innerHTML = oEditDiv.children[1].children[0].value + (oEditDiv.children[1].children[1].value ? "-" + oEditDiv.children[1].children[1].value : '')
                        } else {
                            setCurres[i].children[j].innerHTML = oEditDiv.children[1].children[0].value + (oEditDiv.children[1].children[1].value ? " " + oEditDiv.children[1].children[1].value : "")
                        }
                        setCurres[i].children[j].style.borderColor = "yellow"
                        oEditDiv.style.display = "none"
                        // let id = oEditDiv.getAttribute("data-params")
                        let l_title = ['optionName', 'optionValue', 'optionOtherValue']
                        let obj = {}
                        if (j == 1) {
                            if (i === 0 && j === 1) {
                                obj[l_title[0]] = 'TR::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value

                            } else if (i === 1 && j === 1) {
                                obj[l_title[0]] = 'ZHJL::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else {
                                obj[l_title[0]] = 'RSWDX::' + myselect.value + j
                                obj[l_title[3]] = oEditDiv.children[1].children[0].value
                            }
                            obj[l_title[1]] = oEditDiv.children[1].children[0].value
                        } else if (j == 2) {
                            if (i === 0 && j === 2) {
                                obj[l_title[0]] = 'TR::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else if (i === 1 && j === 2) {
                                obj[l_title[0]] = 'ZHJL::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else {
                                obj[l_title[0]] = 'RSWDX::' + myselect.value + j
                                obj[l_title[3]] = oEditDiv.children[1].children[0].value
                            }
                            obj[l_title[1]] = oEditDiv.children[1].children[0].value
                        } else if (j == 3) {
                            if (i === 0 && j === 3) {
                                obj[l_title[0]] = 'TR::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else if (i === 1 && j === 3) {
                                obj[l_title[0]] = 'ZHJL::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else {
                                obj[l_title[0]] = 'RSWDX::' + myselect.value + j
                                obj[l_title[3]] = oEditDiv.children[1].children[0].value
                            }
                            obj[l_title[1]] = oEditDiv.children[1].children[0].value
                        } else if (j == 4) {
                            if (i === 0 && j === 4) {
                                obj[l_title[0]] = 'TR::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else if (i === 1 && j === 4) {
                                obj[l_title[0]] = 'ZHJL::' + myselect.value + j
                                obj[l_title[2]] = oEditDiv.children[1].children[0].value
                            } else {
                                obj[l_title[0]] = 'RSWDX::' + myselect.value + j
                                obj[l_title[3]] = oEditDiv.children[1].children[0].value
                            }
                            obj[l_title[1]] = oEditDiv.children[1].children[0].value
                        }
                        // 输入框修改接口调用
                        functionName(obj)
                    }
                }
                setCurres[i].children[j].onmouseenter = () => {
                    setCurres[i].children[j].style.borderColor = "red"
                }
                setCurres[i].children[j].onmouseout = () => {
                    setCurres[i].children[j].style.borderColor = "#040a18"
                }

            }
        }
    }
    // 曲线参数修改
    const setDatas = (arr) => { //
        const setCurres = document.querySelector('#zbf_edit_cur1').children
        let l_title = ['optionName', 'optionValue', 'optionOtherValue']
        for (let i = 0; i < setCurres.length; i++) {
            for (let oi = 1; oi < setCurres[i].children.length; oi++) {
                let str = ""
                if (i === 0) {
                    str = arr[i][oi - 1].optionValue
                } else if (i === 1) {
                    str = arr[2][oi - 1].optionValue
                } else if (i === 2) {
                    str = arr[1][oi - 1].optionValue
                } else if (i === 3) {
                    str = arr[3][oi - 1].optionValue
                } else if (i === 4) {
                    str = arr[4][oi - 1].optionValue
                } else if (i === 5) {
                    str = arr[5][oi - 1].optionValue
                }
                setCurres[i].children[oi].innerHTML = str
            }
        }
    }
    // 曲线参数修改
    function getTr(val = 'A') {
        // 初始曲线数据
        request.get('/api/sjdl/option/get/floor/' + val, {}).then(res => {
            console.log(res);
            setDatas(groupObjectsByProperty(res.data, 'optionDescription'))
            // console.log(res.data);
        })
    }
    // 曲线参数修改
    function functionName(obj) {
        request.post('/api/sjdl/option/update', obj).then(res => {
        })
    }
    // 曲线参数修改
    function groupObjectsByProperty(arr, property) {
        const groupedData = {};
        arr.forEach(item => {
            const propValue = item[property];
            // 仅处理中文的optionDescription字段值
            if (/[\u4e00-\u9fa5]/.test(propValue)) {
                const chineseValue = propValue.match(/[\u4e00-\u9fa5]+/)[0];
                if (!groupedData[chineseValue]) {
                    groupedData[chineseValue] = [];
                }
                groupedData[chineseValue].push(item);
            }
        });
        return Object.values(groupedData);
    }
    let delMyData = false
    // 实时信号曲线参数
    let dataIndexOf = document.querySelector('.dataIndexOf')
    $('.xinhaojiapng').onclick = function () {
        dataIndexOf.style.display = 'block'
        flag = true
        let obj = {
            tagName: 'div',
            className: 'xinhaoarrdata',
            children: "",
            attrs: {
                border: '2',
            },
        }
        if ($('.xinhaochangearr').children.length >= 8) {
            dataIndexOf.style.display = 'none'
            flag = false
            alert('最多增加8个选项')
            return
        }
        if ($('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerHTML == "") {
            alert('请先选择参数')
            return
        }
        // shishimyecharts.clear()
        $('.xinhaochangearr').appendChild(render(obj));
    }
    $('.xinhaojianpng').onclick = antiShake(function () {
        let c = document.getElementById("div2");
        if ($('.xinhaochangearr').children.length == 1) {
            alert('最少需要一个选项')
            return
        } else {
            delMyData = true

            if (objDcs.pointIndexList.length > 0) {
                shishiDscRefsresh(objDcs)
            }
            if (objs.pointInfoList.length > 0) {
                shishidatarefsresh(objs)
            }
            console.log(obj.pointIndexList);

            if (obj.pointIndexList.length > 0) {
                dataRefresh(obj)
            }
            // }
            // shishimyecharts.clear()
            c.removeChild(c.lastChild)
        }
    }, 3000)
    let dataselecd = document.querySelector('.dataseles')
    let dataselecdbox = []
    let indexSofa = 0
    async function shishipointName() {
        return request.get('/spf/visit/get/allSourceSelect', {}).then(res => {
            console.log(res, '初始化');
            res.data.sort(function (a, b) {
                return (a.tagDesc + '').localeCompare(b.tagDesc + '')
            })
            dataselecdbox = res.data
            dataselecd.innerHTML = `${res.data.map(item => `<p value="${item.tagName}" text="${item.tagDesc}">${item.tagDesc}</p>`).join('')}`;
            // 搜索文本
            renderInut(res.data[0].tagDesc)

            objs.pointInfoList = [res.data[0].tagName + '::' + res.data[0].tagDesc]

            objsdemo = [res.data[0].tagName + '::' + res.data[0].tagDesc]

            if (indexSofa == 0) {
                shishidatarefsresh(objs)
                indexSofa = 1


            }
            // 单选框
            checkedRdiod()

            let obj = {
                tagName: 'div',
                className: 'xinhaoarrdata',
                children: res.data[0].tagDesc,
                attrs: {
                    border: '2',
                },
            }
            if (data && data.find(item => item.pointDesc == obj.children)) {
                return;
            }
            $('.xinhaochangearr').appendChild(render(obj));
        })


    }
    // 初始化表单数据
    let selecdDcs = document.querySelector('.dataseles')
    let selecData = []
    async function DcsHistoys() {
        return request.get('/api/sjdl/dcsdata/select', {}).then(res => {
            res.data.sort(function (a, b) {
                // console.log(a, b);
                return a.id - b.id
                // return (a.pointName + '').localeCompare(b.pointName + '')
            })
            selecData = res.data
            selecdDcs.innerHTML = `${res.data.map(item => `<p value="${item.dcsName}" text="${item.dcsDesc}">${item.dcsDesc}</p>`).join('')}`;

            DcsHistory(res.data[0].dcsDesc)

            objDcsDemo = [res.data[0].dcsDesc]

            // console.log(objDcsDemo);

            let objDcs = {
                tagName: 'div',
                className: 'xinhaoarrdata',
                children: res.data[0].dcsDesc,
                attrs: {
                    border: '2',
                }
            }

            if (data && data.find(item => item.pointDesc == objDcs.children)) {
                return;
            }
            $('.xinhaochangearr').appendChild(render(objDcs));
            // proxy.selectData = res.data;
        })
    }
    // 搜索文本
    let inpDatas = document.querySelector('.inpDatas')
    function renderInut(key = 'A1 红外特征1') {
        let dataIndexOf = document.querySelector('.dataIndexOf')
        inpDatas.value = key

        //文本框获取焦点
        inpDatas.onfocus = function () {
            dataIndexOf.style.display = 'block'
        }

        inpDatas.oninput = function () {
            let arrs = []
            for (let index = 0; index < dataselecdbox.length; index++) {
                if (dataselecdbox[index].tagDesc.indexOf(inpDatas.value) !== -1) {
                    arrs.push(dataselecdbox[index])
                }
            }
            dataselecd.innerHTML = `${arrs.map(item => `<p value="${item.tagName}" text="${item.tagDesc}">${item.tagDesc}</p>`).join('')}`;
            // 循环点击获取数据
            for (let index = 0; index < dataselecd.children.length; index++) {

                dataselecd.children[index].onclick = function (e) {
                    inpDatas.value = dataselecd.children[index].innerText
                    objs.pointInfoList = [dataselecd.children[index].getAttribute('value') + '::' + dataselecd.children[index].innerText]
                    $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = dataselecd.children[index].innerText
                    let cssdatabox = []
                    for (let i = 0; i < dataselecdbox.length; i++) {
                        for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                            if ($('.xinhaochangearr').children[k].innerText == dataselecdbox[i].tagDesc) {
                                cssdatabox.push(dataselecdbox[i].tagName)
                            }
                        }
                    }
                    dataIndexOf.style.display = 'none'
                    objs.pointInfoList = dataselecdbox.filter(item => cssdatabox.includes(item.tagName)).map(item => item.tagName + '::' + item.tagDesc)
                    shishidatarefsresh(objs, false)
                }
            }
        }

        // select 下拉选中 -- 循环点击获取数据
        for (let index = 0; index < dataselecd.children.length; index++) {
            dataselecd.children[index].onclick = function (e) {
                const currentText = e.target.getAttribute('text');
                console.log('currentText', currentText);

                if (data && data.find(item => item.pointDesc == currentText)) return;
                inpDatas.value = dataselecd.children[index].innerText
                objs.pointInfoList = [dataselecd.children[index].getAttribute('value') + '::' + dataselecd.children[index].innerText]
                // console.log($('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1]);
                $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = dataselecd.children[index].innerText
                let cssdatabox = []
                for (let i = 0; i < dataselecdbox.length; i++) {
                    for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                        if ($('.xinhaochangearr').children[k].innerText == dataselecdbox[i].tagDesc) {
                            cssdatabox.push(dataselecdbox[i].tagName)
                        }
                    }
                }

                dataIndexOf.style.display = 'none'
                objs.pointInfoList = dataselecdbox.filter(item => cssdatabox.includes(item.tagName)).map(item => item.tagName + '::' + item.tagDesc)
                // console.log(cssdatabox);
                shishidatarefsresh(objs, false);
            }

        }

        inpDatas.onblur = function (e) {
            setTimeout(() => {
                dataIndexOf.style.display = 'none'
            }, 400)
        }



    }
    let labelRadio = document.querySelectorAll('.labelRadio label input')
    let arrref = '历史信号'
    let indexDaochu = 0
    let historyTime = true
    let dscTime = false
    let soureTome = false
    function checkedRdiod() {
        // 单选框
        for (let index = 0; index < labelRadio.length; index++) {
            labelRadio[index].onchange = function () {
                indexDaochu = index
                if (labelRadio[index].getAttribute('value') === '历史信号') {
                    shishipointName().then(() => {
                        objs.pointInfoList = objsdemo
                        shishidatarefsresh(objs, true)
                    })
                    // shishimyecharts.clear()
                    dataselecd.innerHTML = ''
                    // $('.xinhaochangearr').innerHTML = ''
                    arrref = '历史信号'
                    // console.log(objs);
                    historyTime = true
                } else if (labelRadio[index].getAttribute('value') === 'Dcs信号') {
                    dataselecd.innerHTML = ''
                    DcsHistoys().then(() => {
                        // shishimyecharts.clear()

                        objDcs.pointIndexList = objDcsDemo
                        // $('.xinhaochangearr').innerHTML = ''
                        shishiDscRefsresh(objDcs, true)

                    })

                    arrref = 'Dcs信号'
                    console.log(objDcs);
                    dscTime = true

                    // 接口


                } else if (labelRadio[index].getAttribute('value') === 'Soure信号') {
                    dataselecd.innerHTML = ''
                    pointName().then(() => {
                        obj.pointIndexList = objdemo
                        dataRefresh(obj, true)
                    })
                    // shishimyecharts.clear()

                    // $('.xinhaochangearr').innerHTML = ''
                    arrref = 'Soure信号'
                    // console.log(obj);
                    soureTome = true

                }
            }
        }
    }

    function DcsHistory(key) {
        inpDatas.value = key
        inpDatas.oninput = function () {
            let arrs = []
            for (let index = 0; index < selecData.length; index++) {
                if (selecData[index].dcsDesc.indexOf(inpDatas.value) !== -1) {
                    arrs.push(selecData[index])
                }
            }
            selecdDcs.innerHTML = `${arrs.map(item => `<p value="${item.dcsName}" text="${item.dcsDesc}">${item.dcsDesc}</p>`).join('')}`;
            // 循环点击获取数据
            for (let index = 0; index < selecdDcs.children.length; index++) {
                selecdDcs.children[index].onclick = function (e) {
                    inpDatas.value = selecdDcs.children[index].innerText
                    objDcs.pointIndexList = [selecdDcs.children[index].getAttribute('text')]
                    $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = selecdDcs.children[index].innerText
                    let cssdatabox = []
                    for (let i = 0; i < selecData.length; i++) {
                        for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                            if ($('.xinhaochangearr').children[k].innerText == selecData[i].dcsDesc) {
                                cssdatabox.push(selecData[i].dcsDesc)
                            }
                        }
                    }
                    dataIndexOf.style.display = 'none'
                    objDcs.pointIndexList = selecData.filter(item => cssdatabox.includes(item.dcsDesc)).map(item => item.dcsDesc)
                    shishiDscRefsresh(objDcs, false)
                }
            }
        }
        // 循环点击获取数据
        for (let index = 0; index < selecdDcs.children.length; index++) {
            selecdDcs.children[index].onclick = function (e) {
                inpDatas.value = selecdDcs.children[index].innerText
                objDcs.pointIndexList = [selecdDcs.children[index].getAttribute('text')]
                $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = selecdDcs.children[index].innerText
                let cssdatabox = []
                for (let i = 0; i < selecData.length; i++) {
                    for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                        if ($('.xinhaochangearr').children[k].innerText == selecData[i].dcsDesc) {
                            cssdatabox.push(selecData[i].dcsDesc)
                        }
                    }
                }
                dataIndexOf.style.display = 'none'
                objDcs.pointIndexList = selecData.filter(item => cssdatabox.includes(item.dcsDesc)).map(item => item.dcsDesc)
                shishiDscRefsresh(objDcs, false);
            }

        }
    }
    let shishidatarefs = []
    let flagSlce = false
    let shishitimerrc = null
    function throttle(fn, interval) {
        var delay = delay || 200;
        var timer;
        return function () {
            var th = this;
            var args = arguments;
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(function () {
                timer = null;
                fn.apply(th, args);
            }, delay);
        };

    }
    $('.btn_select').onclick = throttle(function () {
        console.log('切换数据');
        flagSlce = true
        const domList = $('.canshudate_input', true)
        let sbs = moment(domList[0].value).format('YYYY-MM-DD HH:mm:ss')
        let sbe = moment(domList[1].value).format('YYYY-MM-DD HH:mm:ss');


        console.log(objs);
        if (historyTime) {
            if (objs.pointInfoList.length > 0) {

                // shishimyecharts.clear()
                objs.endTime = sbe
                objs.startTime = sbs

                shishidatarefsresh(objs, true)

            }
        }


        if (soureTome) {
            if (obj.pointIndexList.length > 0) {
                obj.endTime = sbe
                obj.startTime = sbs

                // shishimyecharts.clear();
                dataRefresh(obj, true)
            }
        }
        if (dscTime) {
            if (objDcs.pointIndexList.length > 0) {
                objDcs.endTime = sbe
                objDcs.startTime = sbs

                // shishimyecharts.clear()
                shishiDscRefsresh(objDcs, true)
            }
        }
        // shishimyecharts.clear()
    }, 2000)
    let timeChanged = false
    let xinhaoshishi = ""
    $('.btn_change').onclick = throttle(function () {
        if ($('.shishivalue').innerHTML == "历史信号曲线") {
            $('.valuebox').style.display = "none"
            $('#div2').style.display = "none"
            $('.shishivalue').innerHTML = "实时信号曲线"
            timeChanged = true
            shishitimerrc = setInterval(() => {
                if (xinhaoshishi == "") {

                    shishidatarefsresh(objs, true)

                    if (soureTome) {
                        if (obj.pointIndexList.length > 0) {
                            dataRefresh(obj, true)
                        }
                    }
                    if (dscTime) {
                        if (objDcs.pointIndexList.length > 0) {
                            shishiDscRefsresh(objDcs, true)

                        }
                    }
                    // shishimyecharts.clear()
                }
            }, 3000)
        } else {
            timeChanged = false

            clearInterval(shishitimerrc)
            $('#div2').style.display = "none"
            $('.valuebox').style.display = "flex"
            $('.shishivalue').innerHTML = "历史信号曲线"
        }

    }, 1000)

    // 信号历史查询渲染
    function shishidatarefsresh(objs, isPush = true) {
        if (delMyData) {
            objs.pointInfoList = objs.pointInfoList.filter(item => item.trim() !== $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText.trim())
            shishimyecharts.clear()
            if (objs.pointInfoList.length === 0) {
                return
            }
        }
        let valueList = []
        const domList = $('.canshudate_input', true)
        const mprenow = moment(new Date()).subtract('2', 'minutes').format('YYYY-MM-DD HH:mm:ss')
        const mnow = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');

        // console.log(mprenow, mnow);
        if (timeChanged) {
            objs.startTime = mprenow
            objs.endTime = mnow
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
        } else {
            domList[0].value ? "" : domList[0].value = mprenow;
            domList[1].value ? "" : domList[1].value = mnow;
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
            objs.startTime = valueList[0].replaceAll('T', ' ')
            objs.endTime = valueList[1].replaceAll('T', ' ')
        }
        domList[2].value ? "" : domList[2].value = 1;
        objs.interval = valueList[2]
        request.post('/spf/visit/getSource', objs).then(res => {
            // removeLoader()
            // const shishiCHARTDOM = document.querySelector('#data_canvas');
            shishidatarefs = JSON.parse(JSON.stringify(res.data))
            console.log(objs, '我是soucer列表');

            // console.log(res.data);
            // let arrObj = res.data.map(item => {
            //     return item
            // })
            // for (let key in arrObj[0]) {
            //     shishireflist = shishidatarefs[0][key].dataList
            // }

            // 抽离的图表
            eacherAddS(shishidatarefs, isPush)

        }).catch(res => {
            console.log('错误了:', res);
            // loadingDiv.innerText = res;
            // setTimeout(function () {
            //     document.body.removeChild(loadingDiv)
            // }, 1000)
            // removeLoader()
        })
    }
    // const unique = (arr, key) => {
    //     const res = new Map();
    //     return arr.filter(item => !res.has(item[key]) && res.set(item[key], 1));
    // }
    //去重 将最后的替换之前的
    function unique(arr, key) {
        // if (flagSlce) {
        let uniqueArr = [];
        let uniqueKeys = new Set();

        for (let i = arr.length - 1; i >= 0; i--) {
            let item = arr[i];
            let itemKey = item[key];

            if (!uniqueKeys.has(itemKey)) {
                uniqueArr.unshift(item);
                uniqueKeys.add(itemKey);
            }
        }
        // flagSlce = false
        return uniqueArr;
        // }
        // else {
        //     const res = new Map();
        //     return arr.filter(item => !res.has(item[key]) && res.set(item[key], 1));
        // }

    }
    let data = []
    let datauniqueKeys = []
    function eacherAddS(arrData, isPush = false) {

        arrData = arrData.map((item, index) => {
            const key = Object.keys(item)[0];
            // const obj = {};
            item.pointDesc = key
            return item
        })
        // console.log('isPush', isPush);
        if (delMyData) {

            console.log($('.xinhaochangearr').children);
            let dataMosetdes = JSON.parse(JSON.stringify(data))
            dataMosetdes.splice(data.length - 1, 1)
            data = dataMosetdes

        } else if (!delMyData) {
            if (isPush) {
                data.push(...arrData)
            } else {
                // console.log(data.length, '你跑到添加里面来了');
                if (flag && data.length <= 9 && data.length >= 1) {
                    data.push(...arrData)
                    // console.log(data, arrData);
                    flag = false // 是否点击了添加折线数据
                } else {
                    for (let index = 0; index < arrData.length; index++) {

                        for (let j = 0; j < data.length; j++) {

                            if (arrData[index].pointDesc !== data[j].pointDesc) {

                                data[data.length - 1] = arrData[index];
                                data.push(arrData[index])

                            }
                        }
                    }
                    console.log(data, arrData);

                }
            }
        }
        // let dataQU = JSON.parse(JSON.stringify(data))
        data = unique(data, 'pointDesc')
        console.log(' ', data)
        console.log();
        for (let index = 0; index < $('.xinhaochangearr').children.length; index++) {
            datauniqueKeys.push($('.xinhaochangearr').children[index].innerHTML)
        }
        let pusnData = [...new Set(datauniqueKeys)]
        data.sort((a, b) => {
            let indexA = pusnData.findIndex(obj => obj === a.pointDesc);
            let indexB = pusnData.findIndex(obj => obj === b.pointDesc);
            return indexA - indexB;
        })
        data = unique(data, 'pointDesc')
        console.log(data);
        // Array.from($('.xinhaochangearr').children).sort((a, b) => {
        //     console.log(a, b);
        // })
        delMyData = false
        const COLORS = ['#09d2c0', '#f2c505', '#52d009', '#08ecec', '#52d009'];
        const legend = [];
        let shishioption = {
            // title: {
            //     text: '动态曲线图',
            //     textStyle: {
            //         top: "10px",
            //         color: '#9bdef0'
            //     }
            // },
            grid: {
                top: "20%",
                // right: "30%"
            },
            legend: {
                top: "50px",
                data: objs.pointInfoList,
                textStyle: {
                    color: '#9bdef0',
                    fontFamily: '微软雅黑',
                    fontSize: '18',
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: objs.pointInfoList,
                axisLabel: {
                    show: true,
                    textStyle: {
                        fontFamily: '微软雅黑',
                        color: "#fff",
                        fontSize: '18',
                    }
                }
            },
            tooltip: {
                trigger: 'axis', // 有3个属性值 axis  item  none
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985' //配置展示方块的背景颜色
                    }
                }
            },
            dataZoom: [{
                show: true,
                type: 'inside',
                filterMode: 'none',
                xAxisIndex: [0],
                orient: 'vertical',
            },
            {
                show: true,
                type: 'inside',
                filterMode: 'none',
                yAxisIndex: [0],
                orient: 'vertical',
            }],
            series: [

            ]
        }
        shishioption.series = data.map((item, index) => {
            const key = Object.keys(item)[0];
            const obj = {};
            item.pointDesc = key

            obj.name = item.pointDesc
            obj.emphasis = {
                focus: 'series'
            },
                obj.type = 'line';
            obj.yAxisIndex = index;
            obj.itemStyle = {
                color: COLORS[index]
            };
            let dataList = item[key].dataList

            // const dataList = item[key].dataList.filter((citem, index) => index % 10 === 0)
            obj.data = dataList.map(citem => {
                return {
                    value: [moment(citem.pointTime).format('YYYY-MM-DD HH:mm:ss'), citem[key]]
                };
            });
            obj.data.sort((b, a) => a.value[0].localeCompare(b.value[0]) || a.value[0].localeCompare(b.value[0]));
            dataList.sort((a, b) => a.pointTime.localeCompare(b.pointTime) || a.pointTime.localeCompare(b.pointTime));
            let quchong = {};
            let result = [];
            for (let i = 0; i < dataList.length; i++) {
                if (!quchong[dataList[i].pointTime]) {
                    quchong[dataList[i].pointTime] = true;
                    result.push(dataList[i]);
                }
            }
            dataList = result
            console.log(result);
            shishioption.xAxis.data = dataList.map(citem => moment(citem.pointTime).format('YYYY-MM-DD HH:mm:ss'));
            shishioption.xAxis.yAxisIndex = index;
            // console.log(item[key].pointDesc, legend);
            legend.push(item.pointDesc);
            return obj;
        });

        // console.log(shishioption.series);
        shishioption.legend.data = legend;
        shishioption.color = COLORS;
        let tableData = []
        for (let i = 0; i < legend.length; i++) {
            tableData.push({
                type: 'value',
                //name: element.pointDesc,
                position: i == 0 ? 'left' : "right",
                offset: i * 30,
                nameTextStyle: {
                    color: COLORS[i]
                },
                axisLabel: {
                    formatter: `{value}`,
                    fontFamily: '微软雅黑',
                    color: COLORS[i],
                    fontSize: '18',
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: COLORS[i]
                    }
                },
                type: 'value',
                // min: i == 0 ? xinhaomin : "",
                // max: i == 0 ? xinhaomax : ""
            })
        }
        shishioption.yAxis = tableData
        shishimyecharts.setOption(shishioption);
        console.log(shishioption);

        // loadingDiv.innerText = res.message;
    }



    // dsc信号
    function shishiDscRefsresh(objs, isPush = true) {
        console.log(objs);
        if (delMyData) {
            objs.pointIndexList = objs.pointIndexList.filter(item => item.trim() !== $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText.trim())
            shishimyecharts.clear()
            if (objs.pointIndexList.length === 0) {
                return
            }
        }
        let valueList = []
        let dscShishidatarefs = []
        const domList = $('.canshudate_input', true)
        const mprenow = moment(new Date()).subtract('2', 'minutes').format('YYYY-MM-DD HH:mm:ss')
        const mnow = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
        if (timeChanged) {
            objs.startTime = mprenow
            objs.endTime = mnow
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
        } else {
            domList[0].value ? "" : domList[0].value = mprenow;
            domList[1].value ? "" : domList[1].value = mnow;
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
            objs.startTime = valueList[0].replaceAll('T', ' ')
            objs.endTime = valueList[1].replaceAll('T', ' ')
        }
        domList[2].value ? "" : domList[2].value = 1;
        objs.interval = valueList[2]

        request.post('/api/sjdl/dcsdata/dcshistory', objs).then(res => {
            if (!res.data) return;
            // removeLoader()
            dscShishidatarefs = JSON.parse(JSON.stringify(res.data))
            console.log(objs, '我是dcshistory列表');

            eacherAddS(dscShishidatarefs, isPush)
            // console.log(shishioption)
            // loadingDiv.innerText = res.message;

        }).catch(res => {
            console.log('错误了:', res);
            // loadingDiv.innerText = res;
            // setTimeout(function () {
            //     document.body.removeChild(loadingDiv)
            // }, 1000)
            // removeLoader()
        })
    }
    let shishimyecharts = null;
    const shishiCHARTDOM = document.querySelector('#data_canvas');
    shishimyecharts = echarts.init(shishiCHARTDOM);

    /**实时数据曲线折线图**/
    let myEcharts = null;
    const CHARTDOM = document.querySelector('#data_canvas');
    myEcharts = echarts.init(CHARTDOM);
    let selecd = document.querySelector('.dataseles')
    let pointDataS = []
    async function pointName() {
        return request.get('/spf/visit/get/point', {}).then(res => {
            res.data.sort(function (a, b) {
                return (a.pointName + '').localeCompare(b.pointName + '')
            })
            pointDataS = res.data
            selecd.innerHTML = `${res.data.map(item => `<p value="${item.pointName}" text="${item.pointDescription}">${item.pointDescription}</p>`).join('')}`;
            // 改变选择
            renderChecked(res.data[0].pointDescription)
            objdemo = [res.data[0].pointDescription]
            let obj = {
                tagName: 'div',
                className: 'arrdata',
                children: res.data[0].pointDescription,
                attrs: {
                    border: '2',
                },
            }
            if (data && data.find(item => item.pointDesc == obj.children)) {
                return;
            }
            $('.xinhaochangearr').appendChild(render(obj));
        })


    }

    // 单选框切换
    function renderChecked(key) {
        inpDatas.value = key
        inpDatas.oninput = function () {
            let arrs = []
            for (let index = 0; index < pointDataS.length; index++) {
                if (pointDataS[index].pointDescription.indexOf(inpDatas.value) !== -1) {
                    arrs.push(pointDataS[index])
                }
            }
            selecd.innerHTML = `${arrs.map(item => `<p value="${item.pointName}" text="${item.pointDescription}">${item.pointDescription}</p>`).join('')}`;
            // 循环点击获取数据
            for (let index = 0; index < selecd.children.length; index++) {
                selecd.children[index].onclick = function (e) {
                    inpDatas.value = selecd.children[index].innerText
                    obj.pointIndexList = [selecd.children[index].getAttribute('text')]
                    $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = selecd.children[index].innerText
                    let cssdatabox = []
                    for (let i = 0; i < pointDataS.length; i++) {
                        for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                            if ($('.xinhaochangearr').children[k].innerText == pointDataS[i].pointDescription) {
                                cssdatabox.push(pointDataS[i].pointDescription)
                            }
                        }
                    }
                    dataIndexOf.style.display = 'none'
                    obj.pointIndexList = pointDataS.filter(item => cssdatabox.includes(item.pointDescription)).map(item => item.pointDescription)
                    dataRefresh(obj, false)
                }
            }
        }

        // 循环点击获取数据
        for (let index = 0; index < selecd.children.length; index++) {
            selecd.children[index].onclick = function (e) {
                inpDatas.value = selecd.children[index].innerText
                obj.pointIndexList = [selecd.children[index].getAttribute('text')]
                $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText = selecd.children[index].innerText
                let cssdatabox = []
                for (let i = 0; i < pointDataS.length; i++) {
                    for (let k = 0; k < $('.xinhaochangearr').children.length; k++) {
                        if ($('.xinhaochangearr').children[k].innerText == pointDataS[i].pointDescription) {
                            cssdatabox.push(pointDataS[i].pointDescription)

                        }
                    }
                }
                // console.log(cssdatabox);
                dataIndexOf.style.display = 'none'
                obj.pointIndexList = pointDataS.filter(item => cssdatabox.includes(item.pointDescription)).map(item => item.pointDescription)
                dataRefresh(obj, false)
            }

        }

    }

    // 初始渲染
    function dataRefresh(objdef, isPush = true) {
        console.log(objdef);
        if (delMyData) {
            objdef.pointIndexList = objdef.pointIndexList.filter(item => item.trim() !== $('.xinhaochangearr').children[$('.xinhaochangearr').children.length - 1].innerText.trim())
            shishimyecharts.clear();
            if (objdef.pointIndexList.length === 0) {
                return
            }
        }
        const domList = $('.canshudate_input', true)
        let refList = []
        let valueList = []
        const mprenow = moment(new Date()).subtract('2', 'minutes').format('YYYY-MM-DD HH:mm:ss')
        const mnow = moment(new Date()).subtract('5', 'second').format('YYYY-MM-DD HH:mm:ss');
        if (timeChanged) {
            obj.startTime = mprenow
            obj.endTime = mnow
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
        } else {
            domList[0].value ? "" : domList[0].value = mprenow;
            domList[1].value ? "" : domList[1].value = mnow;
            valueList = [domList[0].value, domList[1].value, domList[2].value || 1];
            objs.startTime = valueList[0].replaceAll('T', ' ')
            objs.endTime = valueList[1].replaceAll('T', ' ')
        }
        domList[2].value ? "" : domList[2].value = 1;
        obj.interval = valueList[2]

        // console.log(objdef);
        request.post('/spf/visit/getHistroy', objdef).then(res => {
            // console.log(objdef, '我是温度稳定');

            // removeLoader();
            refList = JSON.parse(JSON.stringify(res.data))


            // console.log(obj, '历史信号调用');


            eacherAddS(refList, isPush)
        }).catch(res => {
            // loadingDiv.innerText = res;
            // setTimeout(function () {
            //     document.body.removeChild(loadingDiv)
            // }, 1000)
            // removeLoader()
        })

    }
    // 展开点击
    $('.choutileft_header').onclick = function () {
        $('.chouti').className = 'chouti slide-out-right'
        $('.zhankai').className = 'zhankai slide-in-blurred-right'
        setTimeout(function () {
            $('.chouti').style.display = "none"
        }, 800)
    }
    // 收缩点击
    $('.zhankai').onclick = function () {
        $('.chouti').style.display = 'block'
        $('.chouti').className = 'chouti slide-in-blurred-right'
        $('.zhankai').className = 'zhankai slide-out-right'
    }
    //曲线下拉数据更新

    // selecd.onchange = (e) => {
    //     let cssdatabox = []
    //     let csschanggebox = []
    //     for (let i = 0; i < $('.changearr').children.length; i++) {
    //         if ($('.changearr').children[i].innerHTML !== "") {
    //             cssdatabox.push($('.changearr').children[i].innerHTML)
    //         }
    //     }
    //     if (cssdatabox.indexOf(selecd[selecd.selectedIndex].value) == -1) {
    //         $('.changearr').children[$('.changearr').children.length - 1].innerHTML = selecd[selecd.selectedIndex].value
    //     } else {
    //         $('.changearr').children[$('.changearr').children.length - 1].innerHTML = ""
    //     }
    //     for (let i = 0; i < $('.changearr').children.length; i++) {
    //         if ($('.changearr').children[i].innerHTML !== "") {
    //             csschanggebox.push($('.changearr').children[i].innerHTML)
    //         }
    //     }
    //     let objs = {
    //         "endTime": mon(),
    //         "interval": "1",
    //         "pointIndexList": csschanggebox,
    //         "startTime": mons(),
    //     }
    //     obj.pointIndexList = csschanggebox
    //     dataRefresh(objs)
    // }

    // 曲线开始和结束
    function curveData() {
        const curveSubit = document.querySelector('.btn-submit')
        const btnColse = document.querySelector('.btn-colse')
        const myselect = document.querySelector('.qxcsselect')
        curveSubit.onclick = antiShake(function () {
            lsLoader('开启中.......')
            request.post('/api/sjdl/option/start/' + myselect[myselect.selectedIndex].value).then(res => { setTimeout(() => { removeLoader() }, 800) }).catch(err => { })
        }, 2000)
        btnColse.onclick = antiShake(function () {
            lsLoader('关闭中.......')
            request.post('/api/sjdl/option/stop/' + myselect[myselect.selectedIndex].value).then(res => { setTimeout(() => { removeLoader() }, 800) }).catch(err => { })
        }, 2000)
    }

    // 导出参数数据
    $('.btn_export').onclick = function () {
        lsLoader("导出中.....")
        // const loadingDiv = document.createElement('div');
        // loadingDiv.className = 'loading';
        // loadingDiv.innerText = '正在导出...';
        // document.body.appendChild(loadingDiv);
        let params = {};
        let postStr = ''
        if (indexDaochu == 0) {
            params = objs
            postStr = '/api/sjdl/export/excel/source'
        } else if (indexDaochu == 1) {
            params = objDcs
            postStr = '/api/sjdl/export/excel/dcs'
        } else {
            params = obj
            postStr = '/api/sjdl/export/excel/history'
        }
        console.log(params);
        fetch(`${now_open_diag.API_URL + postStr}`, {
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                ...params,
            }),
            method: 'POST'
        }).then(res => {
            return res.blob()
        }).then(async res => {
            // const url = await URL.createObjectURL(res);
            // const aEle = document.createElement('a');
            // aEle.href = url;
            // aEle.style.display = 'none';
            // aEle.download = "参数设置曲线数据.xlsx";
            // aEle.target = '_blank';
            // document.body.appendChild(aEle);
            // aEle.click();
            // document.body.removeChild(aEle);
            // URL.revokeObjectURL(url);
            setTimeout(function () {
                removeLoader()
                // document.body.removeChild(loadingDiv)
            }, 1000)
        })
    }



    // 算法
    let dataArr = []
    let dataLists = []
    let dataSelect = []
    async function initArither() {
        const { data: res } = await request.post('/api/sjdl/option/initialArithmeticProcess')
        dataLists = res
        selects().then(res => {
            initDom()
            ModelData(dataLists)
        })
    }

    async function selects() {
        const { data } = await request.get('/spf/visit/get/getArithmeticOption')
        dataArr = data
    }

    async function initSet(data) {
        await request.post('/api/sjdl/option/updateArithmeticProcess', data)
    }
    async function delData(data) {
        await request.post('/api/sjdl/option/deleteArithmeticProcess', data)
    }
    async function selectAst(floor) {
        const nodeDom = ['温度分析值', '着火距离分度值', '燃烧稳定性分度值']
        let canshupostCont = document.querySelectorAll('.canshupost-cont')
        // 切换之后吧之前的全部清空
        for (let index = 0; index < nodeDom.length; index++) {
            for (let j = 0; j < canshupostCont[index].children.length; j++) {
                canshupostCont[index].children[j].children[1].innerHTML = ''
            }
        }
        let { data } = await request.get('/api/sjdl/option/getArithmeticProcessByFloor/' + floor)
        dataSelect = data

        ModelData(dataSelect)
        // 初始化一下
        initClick()
    }
    // 数据循环加载dom
    function initDom() {
        let str = ''
        const nodeDom = ['温度分析值', '着火距离分度值', '燃烧稳定性分度值']
        let flexBox = document.querySelector('.flex-box')
        for (let id = 0; id < nodeDom.length; id++) {
            str += `
            <div class="canshupost">
                <div class="canshuwendu">${nodeDom[id]}</div>
                <div class="canshupost-close">
                    <div class="hearder">
                       <div> </div>
                        <div class="close-box">x</div>
                    </div>
                    <div class="settom">
                        <div>
                            <span>算法</span>
                            <select class="select-box">
                                <option value="${dataArr[0].optionValue}">${dataArr[0].optionDescription}</option>
                                <option value="${dataArr[1].optionValue}">${dataArr[1].optionDescription}</option>
                                <option value="${dataArr[2].optionValue}">${dataArr[2].optionDescription}</option>
                                <option value="${dataArr[3].optionValue}">${dataArr[3].optionDescription}</option>
                                <option value="${dataArr[4].optionValue}">${dataArr[4].optionDescription}</option>
                                 <option value="${dataArr[5].optionValue}">${dataArr[5].optionDescription}</option>
                            </select>
                        </div>
                        <div class="inp-setbox">
                            <div class="inp-cs">参数1</div>
                            <div class="inpu-value valinput"><input type="text" value="12" style="width: 90px;height: 20px;"></div>
                        </div>
                         <div class="inpVal">
                         <div  class="inp-setbox">
                          <div class="inp-cs1">参数2</div>
                            <div class="inpu-value csninput"><input type="text" value="12" style="width: 90px;height: 20px;">
                         </div>
                        </div>
                        </div>
                    <div class="inpVal1">
                      <div class="inp-setbox">
                        <div class="inp-cs2">参数3</div>
                        <div class="inpu-value csninput1"><input type="text" value="12" style="width: 90px;height: 20px;"></div>
                      </div>
                    </div>
                    </div>
                    <div class="btn-box">
                        <div class="btn-set"><button type="button">删除</button></div>
                        <div class="btn-set1"><button type="button">确定</button></div>
                    </div>
                </div>
               <div class="canshupost-cont">
                <div class="canshupost-box">
                    <div class="canshupost-center">
                        A1
                    </div>
                    <div class="fotos-post">


                    </div>

                    <div class="canshupost-add">+</div>
                </div>
                <div class="canshupost-box">
                    <div class="canshupost-center">
                        A2
                    </div>

                    <div class="fotos-post">

                    </div>

                    <div class="canshupost-add">+</div>
                </div>
                <div class="canshupost-box">
                    <div class="canshupost-center">
                        A3
                    </div>
                    <div class="fotos-post">

                    </div>
                    <div class="canshupost-add">+</div>
                </div>
                <div class="canshupost-box">
                    <div class="canshupost-center">
                        A4
                    </div>
                    <div class="fotos-post">

                    </div>
                    <div class="canshupost-add">+</div>
                </div>
                </div>
            </div>`
            flexBox.innerHTML = str
        }
        Modelview()
    }
    // 循环动态渲染数据
    function setDataModel(arr, index, type, T, scope, addition, denominator, overlimit, coefficient, molecule, coefficientMax, max, secondNumber) {
        arr.innerHTML += `
            <div class="canshupost-mar" name="${index}">
              <span>${nodeSwitch(type)}</span>
                <span style="display:none" class="mar-setpos">${addSwitch(type, T, scope, addition, denominator, overlimit, secondNumber)}</span>
                 <span style="display:none" class="mar-coefficient">${moreSwitch(type, coefficient, molecule, coefficientMax) || 12}</span>
                 <span style="display:none" class="mar-fenzi">${max || 12}</span>
            </div> `
    }

    // 循环动态渲染数据
    function ModelData(dataLists) {
        if (dataLists.length === 0) {
            dataLists.push([], [], [])
        } else if (dataLists.length === 1) {
            dataLists.push([], [])
        } else if (dataLists.length === 2) {
            dataLists.push([])
        }
        const nodeDom = ['温度分析值', '着火距离分度值', '燃烧稳定性分度值']
        let canshupostCont = document.querySelectorAll('.canshupost-cont')
        for (let i = 0; i < nodeDom.length; i++) {
            for (let post = 0; post < dataLists[i].length; post++) {
                if (dataLists[i][post].calculateType === nodeSwitch(nodeDom[0])) {
                    if (canshupostCont[i].children[0].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[0].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[1].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[1].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[2].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[2].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[3].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[3].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }
                }
                if (dataLists[i][post].calculateType === nodeSwitch(nodeDom[1])) {
                    if (canshupostCont[i].children[0].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[0].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[1].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[1].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[2].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[2].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[3].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[3].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }
                }
                if (dataLists[i][post].calculateType === nodeSwitch(nodeDom[2])) {
                    if (canshupostCont[i].children[0].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[0].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[1].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[1].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[2].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[2].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }

                    if (canshupostCont[i].children[3].children[0].innerText.trim() === dataLists[i][post].pointName.trim()) {
                        setDataModel(canshupostCont[i].children[3].children[1], dataLists[i][post].index, dataLists[i][post].type, dataLists[i][post].T, dataLists[i][post].scope, dataLists[i][post].addition, dataLists[i][post].denominator, dataLists[i][post].overlimit, dataLists[i][post].coefficient, dataLists[i][post].molecule, dataLists[i][post].coefficientMax, dataLists[i][post].max, dataLists[i][post].secondNumber)
                    }
                }
            }
        }
        // 初始化一下
        initClick()
    }

    function nodeSwitch(key) {
        let node = {
            '温度分析值': 'Temperature',
            '着火距离分度值': 'IgnitionDistance',
            '燃烧稳定性分度值': 'CombustionStability',
            '1': '一阶惯性算法',
            '2': '幅度约束算法',
            '3': '加法算法',
            '4': '风速影响算法',
            '5': '最大值限制算法',
            '6': '加权滤波算法'
        }
        return node[key]
    }

    function addSwitch(key, T, scope, addition, denominator, overlimit, secondNumber) {
        let node = {
            '1': T,
            '2': scope,
            '3': addition,
            '4': denominator,
            '5': overlimit,
            '6': secondNumber

        }
        return node[key]
    }

    function moreSwitch(key, coefficient, molecule, coefficientMax) {
        let node = {
            '2': coefficient,
            '4': molecule,
            '5': coefficientMax
        }
        return node[key]
    }

    function lessSwitch(e, indexIds, count, indexID, indexs, num) {
        const canshupostClose = document.querySelectorAll('.canshupost-close')
        canshupostClose[count].setAttribute('val', indexIds)
        canshupostClose[count].setAttribute('data-sroce', indexID)
        canshupostClose[indexs].style.left = e.pageX + num + 'px'
    }
    // 算法名字值回显
    function algorithValue(arr, inpNum) {
        let inpVal = document.querySelectorAll('.inpVal')
        let inpVal1 = document.querySelectorAll('.inpVal1')
        let inpCs = document.querySelectorAll('.inp-cs')
        let inpSet = document.querySelectorAll('.inp-cs1')
        let inpMaxDate = document.querySelectorAll('.inp-cs2')
        if (arr === '一阶惯性算法') {
            inpCs[inpNum].innerText = '时间常数'
            inpVal[inpNum].style.display = 'none'
            inpVal1[inpNum].style.display = 'none'
        } else if (arr === '幅度约束算法') {
            inpCs[inpNum].innerText = '幅度'
            inpSet[inpNum].innerText = '系数'
            inpVal1[inpNum].style.display = 'none'
            inpVal[inpNum].style.display = 'block'
        } else if (arr === '加法算法') {
            inpCs[inpNum].innerText = '加法常数'
            inpVal1[inpNum].style.display = 'none'
            inpVal[inpNum].style.display = 'none'
        } else if (arr === '风速影响算法') {
            inpCs[inpNum].innerText = '分母'
            inpSet[inpNum].innerText = '分子'
            inpVal1[inpNum].style.display = 'none'
            inpVal[inpNum].style.display = 'block'
        } else if (arr === '最大值限制算法') {
            inpCs[inpNum].innerText = '超限值'
            inpSet[inpNum].innerText = '约束系数'
            inpMaxDate[inpNum].innerText = '最大值'
            inpVal[inpNum].style.display = 'block'
            inpVal1[inpNum].style.display = 'block'
        } else if (arr === '加权滤波算法') {
            inpCs[inpNum].innerText = '加权常数'
            inpVal[inpNum].style.display = 'none'
            inpVal1[inpNum].style.display = 'none'
        }
    }
    const myselect = document.querySelector('.qxcsselect')
    // 弹窗添加
    function initClick() {
        const nodeDom = ['温度分析值', '着火距离分度值', '燃烧稳定性分度值']
        let canshupostMar = document.querySelectorAll('.canshupost-mar')
        const canshupostClose = document.querySelectorAll('.canshupost-close')
        const closeBox = document.querySelectorAll('.close-box')
        const canshuposts = document.querySelectorAll('.canshupost')
        const btnSet1 = document.querySelectorAll('.btn-set1')
        let selectBox = document.querySelectorAll('.select-box')
        let inpuValue = document.querySelectorAll('.valinput>input')
        const delBtnSet = document.querySelectorAll('.btn-set')
        let csninput = document.querySelectorAll('.csninput>input')
        let maxDate = document.querySelectorAll('.csninput1>input')
        let marSetpos = document.querySelectorAll('.mar-setpos')
        let marCoefficient = document.querySelectorAll('.mar-coefficient')
        let marFenzi = document.querySelectorAll('.mar-fenzi')
        let inpNum = 0
        let indexIds = 0
        let indexID = 0
        let currentName = '';
        let currentValue = 0
        let currentInput = 0
        let currentMaxData = 0
        for (let indexs = 0; indexs < nodeDom.length; indexs++) {

            for (let i = 0; i < canshupostMar.length; i++) {
                canshupostMar[i].onclick = function (e) {
                    indexIds = canshupostMar[i].parentElement.parentElement.children[0].innerText
                    indexID = i

                    setTimeout(() => {
                        inpuValue[inpNum].value = marSetpos[i].innerText
                        csninput[inpNum].value = marCoefficient[i].innerText
                        maxDate[inpNum].value = marFenzi[i].innerText
                        currentValue = marSetpos[i].innerText
                        currentInput = marCoefficient[i].innerText
                        for (var index = 0; index < selectBox[inpNum].options.length; index++) {
                            // 比较下拉框的值，相等就选中它
                            if (selectBox[inpNum].options[index].innerText.trim() == e.target.innerText) {
                                selectBox[inpNum].options[index].selected = true
                            }
                        }
                        // 算法名字值回显
                        algorithValue(canshupostMar[i].children[0].innerText.trim(), inpNum)

                        //  算法名字值切换回显
                        selectBox[inpNum].onchange = function () {
                            algorithValue(selectBox[inpNum].options[selectBox[inpNum].selectedIndex].text.trim(), inpNum)
                        }

                        // 第一个参数
                        inpuValue[inpNum].onchange = function () {
                            currentValue = inpuValue[inpNum].value

                        }

                        // 第二个参数
                        csninput[inpNum].onchange = function () {
                            currentInput = csninput[inpNum].value
                        }

                        // 第三个参数
                        maxDate[inpNum].onchange = function () {
                            currentMaxData = maxDate[inpNum].value
                        }
                    }, 0)

                }
            }


            canshuposts[indexs].onclick = function (e) {
                inpNum = indexs
                if (e.target.parentElement.className == 'canshupost-mar') {
                    canshupostClose[indexs].setAttribute('data-id', indexID)
                    currentName = e.target.parentElement.getAttribute('name');
                    if (indexs === 0) {
                        // console.log(indexID, indexIds);
                        lessSwitch(e, indexIds, 0, indexID, indexs, -50)
                    } else if (indexs === 1) {
                        lessSwitch(e, indexIds, 1, indexID, indexs, -750)
                    } else {
                        lessSwitch(e, indexIds, 2, indexID, indexs, -1500)
                    }
                    canshupostClose[indexs].style.display = 'block'
                    const pageY = e.pageY <= 800 ? 600 : 700;
                    canshupostClose[indexs].style.top = e.pageY - pageY + 'px'
                }
            }


        }

        // 确认按钮

        for (let k = 0; k < nodeDom.length; k++) {
            btnSet1[k].onclick = function (e) {
                // console.log(k);
                // console.log(inpNum, '点击的数字');
                // 切换下拉列表点击数据更变
                // canshupostMar[canshupostClose[k].getAttribute('data-id')].children[0].innerText = seletc
                // console.log(canshupostMar[canshupostClose[k].getAttribute('data-id')].children[0].innerText); // 点击确定的参数值
                let arithmetic = {}
                // console.log('第一个参数', inpuValue[k].value);
                if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '幅度约束算法') {
                    // console.log('第二个参数', csninput[k].value);
                    arithmetic['type'] = '2'
                    arithmetic['scope'] = inpuValue[k].value
                    arithmetic['coefficient'] = csninput[k].value
                } else if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '一阶惯性算法') {
                    arithmetic['type'] = '1'
                    arithmetic['T'] = inpuValue[k].value
                } else if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '加法算法') {
                    arithmetic['type'] = '3'
                    arithmetic['addition'] = inpuValue[k].value
                } else if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '风速影响算法') {
                    arithmetic['type'] = '4'
                    arithmetic['denominator'] = inpuValue[k].value
                    arithmetic['molecule'] = csninput[k].value
                } else if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '最大值限制算法') {
                    arithmetic['type'] = '5'
                    arithmetic['overlimit'] = inpuValue[k].value
                    arithmetic['coefficientMax'] = csninput[k].value
                    arithmetic['max'] = maxDate[k].value
                } else if (selectBox[k].options[selectBox[k].selectedIndex].text.trim() === '加权滤波算法') {
                    arithmetic['type'] = '6'
                    arithmetic['secondNumber'] = inpuValue[k].value
                }
                if ('secondNumber' in arithmetic) {
                    if (+arithmetic?.secondNumber < 11 && +arithmetic?.secondNumber > 0) {
                        if (!Number.isInteger(+arithmetic?.secondNumber)) {
                            return alert('必须为整数');
                        }
                    } else {
                        return alert('加权常数最大值为10')
                    }
                }
                // 点击确认数据改变
                marSetpos[indexID].innerText = currentValue
                marCoefficient[indexID].innerText = currentInput
                marFenzi[indexID].innerText = currentMaxData

                let obj = {
                    pointName: canshupostClose[k].getAttribute('val'),
                    calculateType: nodeSwitch(nodeDom[k]),
                    index: +currentName,
                    arithmetic
                }

                // console.log(obj);
                // 修改接口

                initSet(obj).then(result => {
                    // 点击隐藏
                    selectAst(myselect[myselect.selectedIndex].value)
                    canshupostClose[k].style.display = 'none'
                }).catch(err => {
                    console.log(err);
                });
            }

            // 关闭`
            closeBox[k].onclick = function () {
                canshupostClose[k].style.display = 'none'
            }
            // 删除
            delBtnSet[k].onclick = function (e) {
                let obj = {
                    pointName: canshupostClose[k].getAttribute('val'),
                    calculateType: nodeSwitch(nodeDom[k]),
                    index: +currentName,
                }
                delData(obj).then(res => {
                    // canshupostMar[+canshupostClose[k].getAttribute('data-sroce')].remove()
                    selectAst(myselect[myselect.selectedIndex].value)
                    canshupostClose[k].style.display = 'none'
                }).catch(err => {
                    console.log(err);
                });

            }

        }

    }
    // 添加数据变成弹窗
    function Modelview() {
        // 开始不加就有弹窗事件
        let canshupostAdd = document.querySelectorAll('.canshupost-add')
        let fotosPost = document.querySelectorAll('.fotos-post')
        initClick();
        //   添加
        for (let j = 0; j < canshupostAdd.length; j++) {
            canshupostAdd[j].onclick = function () {
                console.log(fotosPost[j].children.length);
                if (fotosPost[j].children.length > 3) return alert('最多添加四个')
                fotosPost[j].innerHTML += `
                    <div class="canshupost-mar" name=${fotosPost[j].children.length}>
                        <span>一阶惯性算法</span>
                        <span style="display:none" class="mar-setpos">${1200}</span>
                        <span style="display:none" class="mar-coefficient">${12}</span>
                        <span style="display:none" class="mar-fenzi">${123}</span >
                    </div>
                `
                let obj = {
                    pointName: canshupostAdd[j].parentElement.children[0].innerText,
                    calculateType: nodeSwitch(canshupostAdd[j].parentElement.parentElement.parentElement.children[0].innerText),
                    index: fotosPost[j].children.length - 1,
                    arithmetic: {
                        type: '1',
                        T: '1200'
                    }
                }
                initSet(obj)

                // 当我添加了数据(DOM)，进行DOM更新后调用弹窗
                initClick();
            }
        }
    }



    let initSoucre = []
    let selecrSoucer = []
    async function soucreInit() {
        const { data: res } = await request.post('/api/sjdl/source/init')
        initSoucre = res
        initTanChangSoucer()
        SoucerModel(initSoucre)
    }
    // 修改scource算法接口
    async function scoureEadit(data) {
        await request.post('/api/sjdl/source/update', data)
    }
    // 切换scource层数
    async function scoureSlecet(floor) {
        const sourceDom = ['紫外交流', '紫外直流', '红外特征1', '红外特征2', '红外直流', '可见光交流1', '可见光交流2', '可见光直流']
        let TanChangBoxCanshupostCont = document.querySelectorAll('.TanChangBox-canshupost-cont')
        // 切换之后吧之前的全部清空
        for (let index = 0; index < sourceDom.length; index++) {
            for (let j = 0; j < TanChangBoxCanshupostCont[index].children.length; j++) {
                TanChangBoxCanshupostCont[index].children[j].children[1].innerHTML = ''
            }
        }
        const { data: res } = await request.get('/api/sjdl/source/list/' + floor)
        selecrSoucer = res
        SoucerModel(selecrSoucer)
        // 初始化一下
        initTanChuan()
    }
    // 删除delSoucer算法
    async function delSoucer(obj) {
        await request.post('/api/sjdl/source/delete', obj)
    }
    // soruce列表dom动态渲染
    function initTanChangSoucer() {
        const sourceDom = ['紫外交流', '紫外直流', '红外特征1', '红外特征2', '红外直流', '可见光交流1', '可见光交流2', '可见光直流']
        let TanChanglist = document.querySelector('.TanChanglist')
        let str = ''
        for (let id = 0; id < sourceDom.length; id++) {
            str += `
         <div class="TanChangBox">
                        <div class="TanChangBox-source">${sourceDom[id]}</div>
                        <div class="TanChangBox-close">
                            <div class="TanChangBox-hearder">
                                <div> </div>
                                <div class="TanChangBox-close-box">x</div>
                            </div>
                            <div class="TanChangBox-settom">
                                <div>
                                    <span>算法</span>
                                    <select class="TanChangBox-select-box">
                                        <option value="1">一阶惯性算法</option>
                                        <option value="2">加权滤波算法</option>
                                    </select>
                                </div>
                                <div class="TanChangBox-inp-setbox">
                                    <div class="TanChangBox-inp-cs">参数1</div>
                                    <div class="TanChangBox-inpu-value TanChangBox-valinput"><input type="text"
                                            value="12" style="width: 90px;height: 20px;">
                                    </div>
                                </div>
                                <div class="TanChangBox-inpVal">
                                    <div class="TanChangBox-inp-setbox">
                                        <div class="TanChangBox-inp-cs1">参数2</div>
                                        <div class="TanChangBox-inpu-value TanChangBox-csninput"><input type="text"
                                                value="12" style="width: 90px;height: 20px;">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="TanChangBox-btn-box">
                                <div class="TanChangBox-btn-set"><button type="button">删除</button></div>
                                <div class="TanChangBox-btn-set1"><button type="button">确定</button></div>
                            </div>
                        </div>
                        <div class="TanChangBox-canshupost-cont">
                            <div class="TanChangBox-canshupost-box">
                                <div class="TanChangBox-canshupost-center">
                                    A1
                                </div>
                                <div class="TanChangBox-fotos-post">


                                </div>
                                <div class="TanChangBox-canshupost-add">+</div>
                            </div>
                            <div class="TanChangBox-canshupost-box">
                                <div class="TanChangBox-canshupost-center">
                                    A2
                                </div>

                                <div class="TanChangBox-fotos-post">

                                </div>

                                <div class="TanChangBox-canshupost-add">+</div>
                            </div>
                            <div class="TanChangBox-canshupost-box">
                                <div class="TanChangBox-canshupost-center">
                                    A3
                                </div>
                                <div class="TanChangBox-fotos-post">

                                </div>
                                <div class="TanChangBox-canshupost-add">+</div>
                            </div>
                            <div class="TanChangBox-canshupost-box">
                                <div class="TanChangBox-canshupost-center">
                                    A4
                                </div>
                                <div class="TanChangBox-fotos-post">

                                </div>
                                <div class="TanChangBox-canshupost-add">+</div>
                            </div>
                        </div>
                    </div>
        `
            TanChanglist.innerHTML = str
        }
        createAdd()

    }

    // source 字典
    function soucerData(key) {
        let obj = {
            '紫外交流': "IPAC1",
            '紫外直流': "IPVDC",
            '红外特征1': "IRAC1",
            '红外特征2': "IRAC2",
            '红外直流': "IRVDC",
            '可见光交流1': "ISAC1",
            '可见光交流2': "ISAC2",
            '可见光直流': "ISVDC",
            "1": "一阶惯性算法",
            "2": "加权滤波算法"
        }
        return obj[key]
    }

    // Source循环动态渲染数据
    function SourceDataModel(arr, index, type, T, scope, coefficient) {
        arr.innerHTML += `
            <div class="TanChangBox-canshupost-mar" name="${index}">
              <span>${soucerData(type)}</span>
                <span style="display:none" class="TanChangBox-mar-setpos">${addSwitch(type, T, scope)}</span>
                 <span style="display:none" class="TanChangBox-mar-coefficient">${moreSwitch(type, coefficient) || 12}</span>
            </div> `
    }
    function SoucerModel(initSoucre) {
        const sourceDom = ['紫外交流', '紫外直流', '红外特征1', '红外特征2', '红外直流', '可见光交流1', '可见光交流2', '可见光直流']
        let TanChangBoxCanshupostCont = document.querySelectorAll('.TanChangBox-canshupost-cont')
        for (let i = 0; i < sourceDom.length; i++) {
            for (let post = 0; post < initSoucre[i].length; post++) {
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[0]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[1]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[2]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[3]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[4]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[5]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[6]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
                if (initSoucre[i][post].calculateType.trim() === soucerData(sourceDom[7]).trim()) {
                    if (TanChangBoxCanshupostCont[i].children[0].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[0].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[1].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[1].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[2].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[2].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }

                    if (TanChangBoxCanshupostCont[i].children[3].children[0].innerText.trim() === initSoucre[i][post].pointName.trim()) {
                        SourceDataModel(TanChangBoxCanshupostCont[i].children[3].children[1], initSoucre[i][post].index, initSoucre[i][post].type, initSoucre[i][post].T, initSoucre[i][post].scope, initSoucre[i][post].coefficient)
                    }
                }
            }
        }
        // 初始化一下
        initTanChuan()
    }

    // select 回显设置
    function sourceAdd(params, id, key) {
        let TanChangBoxInpCs = document.querySelectorAll('.TanChangBox-inp-cs') // 参数1
        const TanChangBoxInpVal = document.querySelectorAll('.TanChangBox-inpVal') // 参数2 大盒子
        let TanChangBoxInpCs1 = document.querySelectorAll('.TanChangBox-inp-cs1') // 参数2
        let TanChangBoxCsninput = document.querySelectorAll('.TanChangBox-csninput input')// 第二个输入框
        let TanChangBoxValinput = document.querySelectorAll('.TanChangBox-valinput input') // 第一个输入框
        let TanChangBoxMarCoefficient = document.querySelectorAll('.TanChangBox-mar-coefficient')// 隐藏的第二个参数，用作回显
        let TanChangBoxMarSetpos = document.querySelectorAll('.TanChangBox-mar-setpos') // 隐藏的第一个参数，用作回显
        if (key === '加权滤波算法') {
            TanChangBoxInpCs[id].innerText = '加权幅度'
            TanChangBoxInpCs1[id].innerText = '加权系数'
            TanChangBoxInpVal[id].style.display = 'block' // 隐藏 第二个输入框
            TanChangBoxCsninput[id].value = TanChangBoxMarCoefficient[params].innerText // 第二个输入框
            TanChangBoxValinput[id].value = TanChangBoxMarSetpos[params].innerText // 第一个输入框
        } else if (key === '一阶惯性算法') {
            console.log(TanChangBoxMarSetpos[params].innerText, params);
            TanChangBoxInpCs[id].innerText = '时间常数'
            TanChangBoxValinput[id].value = TanChangBoxMarSetpos[params].innerText
            TanChangBoxInpVal[id].style.display = 'none' // 隐藏 第二个输入框
        }
    }

    // soure 弹窗
    function initTanChuan() {
        const sourceDom = ['紫外交流', '紫外直流', '红外特征1', '红外特征2', '红外直流', '可见光交流1', '可见光交流2', '可见光直流']
        let TanChangBoxcanshupostMar = document.querySelectorAll('.TanChangBox-canshupost-mar') // 算法
        const TanChangBoxCloseBox = document.querySelectorAll('.TanChangBox-close-box')
        const TanChangBoxClose = document.querySelectorAll('.TanChangBox-close') // 弹窗
        const TanChangBox = document.querySelectorAll('.TanChangBox')
        const tanchuangSoure = document.querySelector('.tanchuangSoure')
        const tanChangClOSE = document.querySelector('.tangchangClose .close') // 关闭
        const btnSource = document.querySelector('.btn-source') // source 按钮
        const TanChangBoxselectbox = document.querySelectorAll('.TanChangBox-select-box') // 下拉框
        const TanChangBoxBtnSet1 = document.querySelectorAll('.TanChangBox-btn-set1') // 确定
        const TanChangBoxBtnSet = document.querySelectorAll('.TanChangBox-btn-set') // 删除
        let TanChangBoxCsninput = document.querySelectorAll('.TanChangBox-csninput input')// 第二个输入框
        let TanChangBoxValinput = document.querySelectorAll('.TanChangBox-valinput input') // 第一个输入框
        // let TanChangBoxMarCoefficient = document.querySelectorAll('.TanChangBox-mar-coefficient')// 隐藏的第二个参数，用作回显
        // let TanChangBoxMarSetpos = document.querySelectorAll('.TanChangBox-mar-setpos') // 隐藏的第一个参数，用作回显
        let indexDx = 0
        let soucerId = 0
        // let currentValue = '152' // 点击确认替换参数
        // let currentInput = '12'

        // 关闭弹窗
        tanChangClOSE.onclick = function () {
            tanchuangSoure.style.display = 'none'
        }
        // 开启弹窗
        btnSource.onclick = function () {
            tanchuangSoure.style.display = 'block'
        }
        for (let index = 0; index < sourceDom.length; index++) {

            // 设置自定义属性
            TanChangBoxClose[index].setAttribute('data-set', index)

            for (let i = 0; i < TanChangBoxcanshupostMar.length; i++) {

                TanChangBoxcanshupostMar[i].onclick = function () {
                    // 点击的是那个具体算法下标
                    soucerId = i
                    // 使用异步
                    setTimeout(() => {
                        for (let num = 0; num < TanChangBoxselectbox[indexDx].children.length; num++) {

                            if (TanChangBoxselectbox[indexDx].children[num].text.trim() === TanChangBoxcanshupostMar[i].children[0].innerText.trim()) {
                                // 下拉回显
                                TanChangBoxselectbox[indexDx].children[num].selected = true

                            }
                        }

                        sourceAdd(i, indexDx, TanChangBoxcanshupostMar[i].children[0].innerText.trim())

                        // select下拉框切换
                        TanChangBoxselectbox[indexDx].onchange = function () {
                            sourceAdd(i, indexDx, TanChangBoxselectbox[indexDx].options[TanChangBoxselectbox[indexDx].selectedIndex].text.trim())
                        }
                        // 第一个参数
                        // TanChangBoxValinput[indexDx].onchange = function () {
                        //     currentValue = TanChangBoxValinput[indexDx].value
                        // }

                        // // 第二个参数
                        // TanChangBoxCsninput[indexDx].onchange = function () {
                        //     currentInput = TanChangBoxCsninput[indexDx].value
                        // }

                    }, 0)

                }

            }

            // 事件委托
            TanChangBox[index].onclick = function (e) {
                // 先赋值
                indexDx = index
                if (e.target.parentElement.className.trim() === 'TanChangBox-canshupost-mar') {

                    for (let k = 0; k < sourceDom.length; k++) {
                        //每次点击减之前的干掉
                        TanChangBoxClose[k].style.display = 'none'

                        if (+TanChangBoxClose[index].getAttribute('data-set') === index) {
                            // 如果自定义值和点击的值一样就显示
                            TanChangBoxClose[index].style.display = 'block'
                        }
                    }

                    if (index === 0 || index === 4) {
                        TanChangBoxClose[index].style.left = e.pageX + 50 + 'px'
                    } else if (index === 1 || index === 5) {
                        TanChangBoxClose[index].style.left = e.pageX - 410 + 'px'
                    } else if (index === 2 || index === 6) {
                        TanChangBoxClose[index].style.left = e.pageX - 900 + 'px'
                    } else if (index === 3 || index === 7) {
                        TanChangBoxClose[index].style.left = e.pageX - 1480 + 'px'
                    }
                    if (index >= 4) {
                        TanChangBoxClose[index].style.top = e.pageY - 620 + 'px'
                    } else {
                        TanChangBoxClose[index].style.top = e.pageY - 200 + 'px'
                    }

                }
            }
            //确定
            TanChangBoxBtnSet1[index].onclick = function () {
                let arithmetic = {}
                if (TanChangBoxselectbox[index].options[TanChangBoxselectbox[index].selectedIndex].text.trim() === '一阶惯性算法') {
                    arithmetic['type'] = '1'
                    arithmetic['T'] = TanChangBoxValinput[index].value
                } else if (TanChangBoxselectbox[index].options[TanChangBoxselectbox[index].selectedIndex].text.trim() === '加权滤波算法') {
                    arithmetic['type'] = '2'
                    arithmetic['scope'] = TanChangBoxValinput[index].value
                    arithmetic['coefficient'] = TanChangBoxCsninput[index].value
                }
                // console.log(currentValue, currentInput, index);
                // TanChangBoxMarSetpos[index].innerText = currentValue
                // TanChangBoxMarCoefficient[index].innerText = currentInput
                let obj = {
                    calculateType: soucerData(sourceDom[index]),
                    index: +TanChangBoxcanshupostMar[soucerId].getAttribute('name'),
                    pointName: TanChangBoxcanshupostMar[soucerId].parentElement.parentElement.children[0].innerText,
                    arithmetic
                }
                scoureEadit(obj).then((res) => {
                    scoureSlecet(myselect[myselect.selectedIndex].value)
                    TanChangBoxClose[index].style.display = 'none'
                })
            }
            // 删除

            TanChangBoxBtnSet[index].onclick = function () {
                let obj = {
                    pointName: TanChangBoxcanshupostMar[soucerId].parentElement.parentElement.children[0].innerText,
                    calculateType: soucerData(sourceDom[index]),
                    index: +TanChangBoxcanshupostMar[index].getAttribute('name'),
                }
                delSoucer(obj).then(() => {
                    scoureSlecet(myselect[myselect.selectedIndex].value)
                    TanChangBoxClose[index].style.display = 'none'
                })

            }

            // 弹窗点击X关闭
            TanChangBoxCloseBox[index].onclick = function () {
                TanChangBoxClose[index].style.display = 'none'
            }
        }

    }

    // scoure 添加
    function createAdd() {
        initTanChuan()
        const TanChangBoxCanshupostAdd = document.querySelectorAll('.TanChangBox-canshupost-add')
        let TanChangBoxFotosPost = document.querySelectorAll('.TanChangBox-fotos-post')
        for (let j = 0; j < TanChangBoxCanshupostAdd.length; j++) {
            TanChangBoxCanshupostAdd[j].onclick = antiShake(function () {
                if (TanChangBoxFotosPost[j].children.length > 1) return alert('最多添加二个')
                TanChangBoxFotosPost[j].innerHTML += `
                    <div class="TanChangBox-canshupost-mar" name=${TanChangBoxFotosPost[j].children.length}>
                        <span>一阶惯性算法</span>
                       <span style="display:none" class="TanChangBox-mar-setpos">${12}</span>
                       <span style="display:none" class="TanChangBox-mar-coefficient">${12}</span>
                    </div>
                `
                let obj = {
                    calculateType: soucerData(TanChangBoxCanshupostAdd[j].parentElement.parentElement.parentElement.children[0].innerText).trim(),
                    index: +TanChangBoxFotosPost[j].children.length - 1,
                    pointName: TanChangBoxCanshupostAdd[j].parentElement.children[0].innerText,
                    arithmetic: {
                        type: '1',
                        T: '1200'
                    }
                }

                scoureEadit(obj).then(() => {
                    scoureSlecet(myselect[myselect.selectedIndex].value)
                })
                initTanChuan()

            }, 3000)
        }

    }
})()
